package flatlandRPGTest;

import org.lwjgl.input.Keyboard;
import flatlandRPG.TestableKeyboard;
import org.lwjgl.util.vector.Vector2f;
import flatlandRPG.GameText;
import flatlandRPG.Actor;
import student.*;

// -------------------------------------------------------------------------
/**
 * Tests the Actor class.
 *
 * @author evant
 * @version May 1, 2011
 */
public class ActorTest
    extends GUITestCase
{
    private Actor actor;


    public void setUp()
    {
        actor =
            new Actor(0.2f, 5, new GameText(100), "Test text", "Test text 2");
    }


    // ----------------------------------------------------------
    /**
     * Tests that a conversation takes place if the player is close to the
     * actor.
     */
    public void testTalking()
    {
        assertFalse(actor.isConversing());

        actor.talk(new Vector2f(0, 0));

        assertTrue(actor.isConversing());
    }


    // ----------------------------------------------------------
    /**
     * Tests that a conversation does not take place if the player is far away.
     */
    public void testNotTalking()
    {
        actor.talk(new Vector2f(2, 2));

        assertFalse(actor.isConversing());
    }


    // ----------------------------------------------------------
    /**
     * Tests that each successive press of the 'use' key moves the conversation
     * forward.
     */
    public void testDoLogic()
    {
        actor.talk(new Vector2f(0, 0));
        TestableKeyboard.setKeyDown(Keyboard.KEY_E);
        actor.doLogic();

        assertEquals("Test text", actor.getText());

        TestableKeyboard.setKeyUp(Keyboard.KEY_E);
        actor.doLogic();

        TestableKeyboard.setKeyDown(Keyboard.KEY_E);
        actor.doLogic();

        assertEquals("Test text 2", actor.getText());

        TestableKeyboard.setKeyUp(Keyboard.KEY_E);
        actor.doLogic();

        TestableKeyboard.setKeyDown(Keyboard.KEY_E);
        actor.doLogic();

        assertNull(actor.getText());
    }

    // ----------------------------------------------------------
    /**
     * Tests that getText returns the right thing.
     */
    public void testGetText() {
        actor.talk(new Vector2f(0, 0));

        assertNull(actor.getText());

        TestableKeyboard.setKeyDown(Keyboard.KEY_E);
        actor.doLogic();

        assertEquals("Test text", actor.getText());
    }
}
